package com.licode.codekit;

import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;

import java.io.File;

public class ActionEventUtil {
    public static void handleEvent(AnActionEvent e) {
        IdeView ideView = e.getRequiredData(LangDataKeys.IDE_VIEW);
        if (ideView.getOrChooseDirectory() != null) {
            String strPath = ideView.getOrChooseDirectory().getVirtualFile().getPath() + "/pom.xml";
            e.getPresentation().setEnabled(new File(strPath).exists());
        }
    }

    public static void handleDirEvent(AnActionEvent e) {
        IdeView ideView = e.getRequiredData(LangDataKeys.IDE_VIEW);
        if (ideView.getOrChooseDirectory() != null) {
            String strPath = ideView.getOrChooseDirectory().getVirtualFile().getPath();
            File file = new File(strPath);
            e.getPresentation().setEnabled(file.exists() && file.isDirectory());
        }
    }
}
